//
//  EmoticonPackage.swift
//  02-表情键盘
//
//  Created by  NorthCity on 15/11/13.
//  Copyright © 2015年  NorthCity. All rights reserved.
//

import UIKit

class EmoticonPackage: NSObject {
///    表情包路径名
    var id:String?
///    表情包名字
    var group_name_cn:String?
///    表情包数组
    lazy var emoticons = [Emoticon]()

    
    init(dict:[String:AnyObject]) {
       super.init()
        id = dict["id"] as? String
        var index = 0
        group_name_cn = dict["group_name_cn"] as? String
        if let array = dict["emoticons"] as?[[String:String]] {
            for var d in array {
                if let png = d["png"],let dir = id{
                    d["png"] = dir + "/" + png
                }
                emoticons.append(Emoticon(dict: d))
                if ++index == 20 {
                    emoticons.append(Emoticon(isRemoved: true))
                    index = 0
                }
            }
        }
        addEmptyButton()
    }
    
    private func addEmptyButton(){
        let count = emoticons.count%21
        if emoticons.count > 0 && count == 0{
            return
        }
        for _ in count..<20{
            emoticons.append(Emoticon(isEmpty: true))
        }
        emoticons.append(Emoticon(isRemoved: true))
    }
    
  override  var description:String{
        let keys = ["id","group_name_cn","emoticons"]
        return  dictionaryWithValuesForKeys(keys).description
    }
    
}
